package com.testplatform.aitestplatform.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.testplatform.aitestplatform.domain.TestCases;
import com.testplatform.common.annotation.Log;
import com.testplatform.common.core.controller.BaseController;
import com.testplatform.common.core.domain.AjaxResult;
import com.testplatform.common.core.domain.R;
import com.testplatform.common.core.page.TableDataInfo;
import com.testplatform.common.enums.BusinessType;
import com.testplatform.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.testplatform.aitestplatform.domain.AiUseCaseGeneration;
import com.testplatform.aitestplatform.service.IAiUseCaseGenerationService;


/**
 * 用例生成Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@Api("用例生成管理")
@RestController
@RequestMapping("/aitestplatform/generation")
public class AiUseCaseGenerationController extends BaseController
{
    @Autowired
    private IAiUseCaseGenerationService aiUseCaseGenerationService;

    /**
     * 查询用例生成列表
     */
    @ApiOperation("查询用例生成列表")
    @PreAuthorize("@ss.hasPermi('aitestplatform:generation:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam("查询条件对象") AiUseCaseGeneration aiUseCaseGeneration)
    {
        startPage();
        List<AiUseCaseGeneration> list = aiUseCaseGenerationService.selectAiUseCaseGenerationList(aiUseCaseGeneration);
        return getDataTable(list);
    }

    /**
     * 导出用例生成列表
     */
    @ApiOperation("导出用例生成列表")
    @PreAuthorize("@ss.hasPermi('aitestplatform:generation:export')")
    @Log(title = "用例生成", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@ApiParam("导出的查询条件") HttpServletResponse response, AiUseCaseGeneration aiUseCaseGeneration)
    {
        List<AiUseCaseGeneration> list = aiUseCaseGenerationService.selectAiUseCaseGenerationList(aiUseCaseGeneration);
        ExcelUtil<AiUseCaseGeneration> util = new ExcelUtil<AiUseCaseGeneration>(AiUseCaseGeneration.class);
        util.exportExcel(response, list, "用例生成数据");
    }

    /**
     * 获取用例生成详细信息
     */
    @ApiOperation("获取用例生成详细信息")
    @PreAuthorize("@ss.hasPermi('aitestplatform:generation:query')")
    @GetMapping(value = "/{id}")
    public R<AiUseCaseGeneration> getInfo(@PathVariable("id") @ApiParam("用例生成ID") Long id)
    {
        return R.ok(aiUseCaseGenerationService.selectAiUseCaseGenerationById(id));
    }

    /**
     * 新增用例生成
     */
    @ApiOperation("新增用例生成")
    @PreAuthorize("@ss.hasPermi('aitestplatform:generation:add')")
    @Log(title = "用例生成", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @ApiParam("新增的用例生成对象") AiUseCaseGeneration aiUseCaseGeneration)
    {
        return toAjax(aiUseCaseGenerationService.insertAiUseCaseGeneration(aiUseCaseGeneration));
    }

    /**
     * 修改用例生成
     */
    @ApiOperation("修改用例生成")
    @PreAuthorize("@ss.hasPermi('aitestplatform:generation:edit')")
    @Log(title = "用例生成", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @ApiParam("修改的用例生成对象") AiUseCaseGeneration aiUseCaseGeneration)
    {
        return toAjax(aiUseCaseGenerationService.updateAiUseCaseGeneration(aiUseCaseGeneration));
    }

    /**
     * 删除用例生成
     */
    @ApiOperation("删除用例生成")
    @PreAuthorize("@ss.hasPermi('aitestplatform:generation:remove')")
    @Log(title = "用例生成", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable @ApiParam("要删除的用例生成ID") Long[] ids)
    {
        return toAjax(aiUseCaseGenerationService.deleteAiUseCaseGenerationByIds(ids));
    }

    @ApiOperation("生成用例")
    @PostMapping("generatedTestCase")
    public R<List<TestCases>>  generatedTestCase(@RequestBody @ApiParam("要生成的用例生成对象") AiUseCaseGeneration aiUseCaseGeneration){
        List<TestCases> testCases =aiUseCaseGenerationService.generatedTestCaseAi(aiUseCaseGeneration);

        return R.ok(testCases);
    }


}
